package com.freecloud.bitorrent.enums;

import cn.hutool.core.lang.Assert;

/**
 * @Author: maomao
 * @Date: 2022/7/15 3:58 PM
 */
public enum MessageTypeEnum {

    /**
     * 查询
     */
    Query("q"),
    /**
     * 响应
     */
    Return("r"),
    /**
     * 错误
     */
    Error("e");

    private String value;

    MessageTypeEnum(String value) {
        this.value = value;
    }

    public static MessageTypeEnum getQueryEnum(String value) {
        Assert.notBlank(value);
        for (MessageTypeEnum typeEnum : MessageTypeEnum.values()) {
            if (typeEnum.getValue().equals(value)) {
                return typeEnum;
            }
        }
        throw new RuntimeException("not find " + value);
    }

    public String getValue() {
        return value;
    }
}
